# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Davorin Učakar <davorin.ucakar@gmail.com>

pkgname=libsquish
pkgver=1.15
pkgrel=7
pkgdesc='DXT compression library'
arch=(loong64 x86_64)
url='https://sourceforge.net/projects/libsquish'
license=(MIT)
makedepends=(cmake ninja setconf)
source=("https://downloads.sourceforge.net/project/libsquish/libsquish-$pkgver.tgz") # exploding tarball
b2sums=('d2cdf274baf9cf8890ee4c5c434448a34bc6d3d8967df6e2e9334fe1eff66ce5371597396c564c80a128709a8849f1f622d90aaf470eacc1ad67811cef38bd60')

prepare() {
  setconf config USE_OPENMP 0
  setconf config USE_SHARED 1
  setconf config USE_SSE 1
  setconf libsquish.pc.in Version "$pkgver"
}

build() {
  cmake \
    -B build \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D BUILD_SHARED_LIBS=ON \
    -G Ninja \
    -S .
  ninja -C build
}

package() {
  (cd build; cmake -D CMAKE_INSTALL_PREFIX="$pkgdir/usr" -P cmake_install.cmake)
  install -Dm644 CMakeModules/FindlibSquish.cmake "$pkgdir/usr/share/cmake/Modules/FindlibSquish.cmake"
  install -Dm644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  INSTALL_DIR="$pkgdir" LIB_PATH=usr/lib make uninstall install
  rm -frv "$pkgdir/include"
}
